import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/list.dart';

class CustomCountPanel extends StatelessWidget {
  const CustomCountPanel({
    required this.counts,
    super.key,
    this.valStyle,
    this.titleStyle,
  });

  /// eg: {'已完成': '0个', '完成率': '0%'}
  final Map<String, String> counts;
  final TextStyle? valStyle;
  final TextStyle? titleStyle;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: const Color(0x1A5C6DFF),
        borderRadius: BorderRadius.circular(7.w),
      ),
      padding: EdgeInsets.all(10.w),
      child: LayoutBuilder(builder: (_, constrains) {
        final width = constrains.maxWidth - 1.w * counts.length;
        final perWidth = width / counts.length;
        return Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: counts.keys
              .map((e) {
                final val = counts[e];
                // ignore: unnecessary_cast
                return SizedBox(
                  width: perWidth,
                  child: Column(
                    children: [
                      Text(
                        val ?? '0',
                        style: TextStyle(
                          color: Colors.blue,
                          fontWeight: FontWeight.w500,
                          fontSize: 12.w,
                        ),
                      ),
                      Text(
                        e,
                        style: TextStyle(
                          color: Colors.blue,
                          fontSize: 12.w,
                        ),
                      ),
                    ],
                  ),
                ) as Widget;
              })
              .toList()
              .joinWith(
                Container(
                  height: 24.w,
                  width: 1,
                  color: Colors.white,
                ),
              ),
        );
      }),
    );
  }
}
